GtkTimeline: protect the timeline from unref
authorRyan Lortie <desrt@desrt.ca>
Wed, 25 Jan 2012 16:30:11 +0000 (11:30 -0500)
committerRyan Lortie <desrt@desrt.ca>
Thu, 26 Jan 2012 01:29:31 +0000 (20:29 -0500)
The timeline frame function emits several signals, assuming that the
timeline will exist after these signals return.  This assumption can be
invalid if signal handlers unref the timeline.

https://bugzilla.gnome.org/show_bug.cgi?id=668675

gtk/gtktimeline.c

index db9b0beca2ecac803c811540f8744a8fd4f63ec2..5744e4bfff28feaed5add5ba6fce18642e193308 100644 (file)
@@ -311,6 +311,9 @@ gtk_timeline_run_frame (GtkTimeline *timeline)
   gdouble delta_progress, progress;
   guint elapsed_time;
 
+  /* the user may unref us during the signals, so save ourselves */
+  g_object_ref (timeline);
+
   priv = timeline->priv;
 
   elapsed_time = (guint) (g_timer_elapsed (priv->timer, NULL) * 1000);
@@ -355,10 +358,13 @@ gtk_timeline_run_frame (GtkTimeline *timeline)
             }
           g_timer_stop (priv->timer);
           g_signal_emit (timeline, signals [FINISHED], 0);
+          g_object_unref (timeline);
           return FALSE;
         }
     }
 
+  g_object_unref (timeline);
+
   return TRUE;
 }